# Yaya项目构建脚本

# 配置
PROJECT_NAME = yaya
VERSION = 0.1.0
BUILD_DIR = target
RELEASE_DIR = $(BUILD_DIR)/release
DEBUG_DIR = $(BUILD_DIR)/debug

# 工具
CARGO = cargo
ZIG = zig
RM = rm -rf
MKDIR = mkdir -p

# 默认目标
.PHONY: all
all: debug

# 调试构建
.PHONY: debug
debug:
	@echo "构建调试版本..."
	$(CARGO) build
	@echo "调试构建完成"

# 发布构建
.PHONY: release
release:
	@echo "构建发布版本..."
	$(CARGO) build --release
	@echo "发布构建完成"

# 运行示例
.PHONY: examples
examples: debug
	@echo "运行示例应用..."
	$(CARGO) run --bin yaya_loader hello
	$(CARGO) run --bin yaya_loader minimal

# 运行测试
.PHONY: test
test:
	@echo "运行测试..."
	$(CARGO) test
	$(CARGO) run --bin yaya_loader test

# 清理构建文件
.PHONY: clean
clean:
	@echo "清理构建文件..."
	$(RM) $(BUILD_DIR)
	$(CARGO) clean

# 格式化代码
.PHONY: fmt
fmt:
	@echo "格式化代码..."
	$(CARGO) fmt

# 代码检查
.PHONY: lint
lint:
	@echo "运行代码检查..."
	$(CARGO) clippy

# 文档生成
.PHONY: doc
doc:
	@echo "生成文档..."
	$(CARGO) doc --no-deps --open

# 安装依赖
.PHONY: deps
deps:
	@echo "安装依赖..."
	$(CARGO) update

# 构建Zig组件
.PHONY: zig-build
zig-build:
	@echo "构建Zig组件..."
	cd zig_components && $(ZIG) build

# 完整构建（包含所有组件）
.PHONY: full-build
full-build: deps zig-build release
	@echo "完整构建完成"

# 帮助信息
.PHONY: help
help:
	@echo "Yaya项目构建系统"
	@echo ""
	@echo "可用目标:"
	@echo "  all         - 默认构建（调试版本）"
	@echo "  debug       - 构建调试版本"
	@echo "  release     - 构建发布版本"
	@echo "  examples    - 运行示例应用"
	@echo "  test        - 运行测试"
	@echo "  clean       - 清理构建文件"
	@echo "  fmt         - 格式化代码"
	@echo "  lint        - 代码检查"
	@echo "  doc         - 生成文档"
	@echo "  deps        - 安装依赖"
	@echo "  zig-build   - 构建Zig组件"
	@echo "  full-build  - 完整构建（所有组件）"
	@echo "  help        - 显示此帮助信息"